package br.com.estagio.domain.dao;

import java.util.List;

import br.com.estagio.domain.entity.EntityAbstract;
import br.com.estagio.domain.entity.Pais;


public class DaoPais extends Dao{

	@Override
	public List<Pais> listAll() {
		try {
			final String HQL = "FROM Pais pais";
			return this.manager.createQuery(HQL, Pais.class).getResultList();
		} catch (Exception e) {
			this.rollback();
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public EntityAbstract findById(Integer id) {
		try {
			return this.getManager().find(Pais.class, id);
		} catch (Exception e) {
			this.rollback();
			e.printStackTrace();			
		}		
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public List<Pais> filter(Pais pais) {
		String sql = "SELECT id, pais, sigla, ddi FROM Pais pais WHERE " +
				 " pais.pais like '%" + pais.getPais() + "%'";
		return this.manager.createNativeQuery(sql, Pais.class).getResultList();	
	}

}
